package br.com.acs.CameraIP.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;

import br.com.acs.CameraIP.dao.ClienteDao;
import br.com.acs.CameraIP.dao.ClienteDaoImp;
import br.com.acs.CameraIP.model.Cliente;

@FacesConverter(forClass=Cliente.class, value="clienteConverter")
public class ClienteConverter implements Converter{

	@Override
	public Object getAsObject(FacesContext arg0, UIComponent arg1, String arg2) {
		
		return null;
	}

	@Override
	public String getAsString(FacesContext arg0, UIComponent arg1, Object arg2) {
		try {
  		   if(arg2 != null){
			  ClienteDao dao = new ClienteDaoImp();
			  Cliente empresa = dao.getCliente((Long) arg2);
		      return empresa.getRazaoSocial();
		  }
		  return null;
	   } catch (Exception e ){
		  return null;
       }
	}   
}


